<?php
namespace app\api\controller;
use app\user\controller\User;
use think\Db;
class Logintoken extends Authinfo
{
//用户登录接口
    public function login(){
		$username=input('username');
		$password=input('password');

			$User   =   new User();
			$uid    =   $User->login($username,$password,$type=1);

			$info=Db::name('Member')->where('id',$uid)->field('id,username,nickname,sfid,townsid,sex,zu,mobile')->find();
			if($info){
				$info['tname']=get_alltowns($info['townsid']);
				$info['sex']=get_sex($info['sfid']);
				$info['uid']=$info['id'];
				$datas['status']=1;
				$datas['info']=$info;
			}else{
				$datas['status']=0;
				$datas['info']='登录失败！账号密码不匹配';
			}

		return json($datas);

    }




    public function getversion(){
       $version=input('version');
       if($version){
         $info=Db::name('Version')->order('create_time DESC')->find();
         if($info){
			 $info['rompath']=ROOT_URL.$info['rompath'];
			 if($info['beizhu']){

			 }else{
				 $info['beizhu']='';
			 }
          if($info['version']==$version){
             $datas['status']=0;

             $datas['info']='无更新！';
          }else{
            $datas['status']=1;
            $datas['info']=$info;
          }
         }else{
          $datas['status']=0;
          $datas['info']='无信息！';
         }
       }else{
         $datas['status']=0;
         $datas['info']='无参数！';
       }
       return json($datas);
    }

    public function changepassword(){
        $username=input('username');
        $sfid=input('sfid');
        $password=input('password');
        if($username && $sfid){
            $cz=DB::name('Member')->where('username',$username)->where('sfid',$sfid)->find();
            if($cz){
                $data['password']=hb_member_md5($password, HB_AUTH_KEY);
                if($data){
                    $ids=DB::name('Member')->where('sfid',$sfid)->update($data);
                    if($ids){
                        $datas['status']=1;
                        $datas['info']='重置成功';
                    }else{
                        $datas['status']=0;
                        $datas['info']='重置失败';
                    }
                }else{
                    $datas['status']=0;
                    $datas['info']='密码不能为空';
                }
            }else{
                $datas['status']=0;
                $datas['info']='信息不存在！';
            }
        }else{
            $datas['status']=0;
            $datas['info']='无参数！';
        }
        return json($datas);
    }







}
